using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace InventorySystem
{
    public class InventoryInputHandler : MonoBehaviour
    {
        private Inventory _inventory;

        // 初始化_inventory变量
        private void Awake()
        {
            _inventory = GetComponent<Inventory>();
        }

        // 每帧检查是否响应按键
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.G))
            { // 如果按下G键
                OnThrowItem(); // 丢弃物品
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                OnPreviousItem(); // 选择上一项
            }
            if (Input.GetKeyDown(KeyCode.E))
            {
                OnNextItem(); // 选择上一项
            }
        }

        // 丢弃当前物品
        private void OnThrowItem()
        {
            _inventory.RemoveItem(_inventory.ActiveSlotIndex, true);
        }

        // 选择下一项物品
        private void OnNextItem()
        {
            _inventory.ActivateSlot(_inventory.ActiveSlotIndex + 1);
        }

        // 选择上一项物品
        private void OnPreviousItem()
        {
            _inventory.ActivateSlot(_inventory.ActiveSlotIndex - 1);
        }
    }
}
